home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Reference Guide
/
C-C++ Interactive Reference Guide.iso
/
c_ref
/
csource5
/
352_01
/
strppsqz.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1991-04-30
|
1KB
|
50 lines
// STRPPSQZ.CPP contains String::squeeze
// string squeeze. Any chars in s2 are removed from s1.
// METHOD: s pts to source string.
// p starts out at same place.
// for every char to keep, *s = *p and both are incremented.
// for every char to loose, p is incremented, s left alone.
//
//
#include <stdlib.h>
#include <string.h>
#include "dblib.h"
String& String::squeeze (char *tok )
{
char *lag = s; // ptr to remaining part of string
char *lead=lag; // ptr to exploring part of string
if ( ! (lag ==NULL || tok==NULL ) )
{
int ntok = strlen(tok);
char c;
int offset =0;
for ( ; *lead; ++lead)
{
c = *lead;
if ( -1 == String::findchr ( tok, ntok, c ) )
{
/* character at p is not contained in s2,
* so copy it to s and move offset on lagging ptr up one.
*/
lag[offset++] = c;
}
}
lag[offset] =0;
n = offset;
if ( offset ==0 )
{
// entire string was squeezed,
destruct();
}
}
return *this; /* strsqz() */
}
/*-------------------- end of strsqz() ----------------------------- */